package com.testDemo.controller;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.testDemo.enrty.AopTestException;
import com.testDemo.enrty.TestDemoResult;
import com.testDemo.service.TestDemoService;

/**
 * @author cuij
 * @version 创建时间：2017-6-13 上午11:28:55
 *          程序的简单说明
 */
@Controller
@RequestMapping("/create")
public class MethodPageController {

    @Resource
    private TestDemoService testDemo;

    /**
     * 根据接口名获取接口对应的页面,先查库,查询不到则读取excel模板生成
     * @param methodName
     * @return
     * @throws Exception
     */
    @ResponseBody
    @RequestMapping("/getMethodPage.do")
    public TestDemoResult getMethodPage(String methodName) throws Exception {
        TestDemoResult result = null;
        try {
            result = testDemo.getMethodPage(methodName);
        }
        catch (AopTestException e) {
            result = new TestDemoResult(e.getCode(), e.getDetail(), "");
        }
        catch (Exception e) {
            e.printStackTrace();
            result = new TestDemoResult(TestDemoResult.ERROR_CODE, e.getMessage(), "");
        }
        return result;
    }

    /**
     * 获取所有的method列表
     * @return
     */
    @ResponseBody
    @RequestMapping("/getMethodList.do")
    public TestDemoResult getMethodList() {
        TestDemoResult result = null;
        try {
            result = testDemo.getMethodList();
        }
        catch (AopTestException e) {
            result = new TestDemoResult(e.getCode(), e.getDetail(), "");
        }
        catch (Exception e) {
            e.printStackTrace();
            result = new TestDemoResult(TestDemoResult.ERROR_CODE, e.getMessage(), "");
        }
        return result;
    }

    /**
     * 获取全量的appkey,并返回其对应的省份和下属工号
     * @return
     * @throws Exception
     */
    @ResponseBody
    @RequestMapping("/getAppkeyList.do")
    public TestDemoResult getAppkeyList() throws Exception {
        TestDemoResult result = null;
        try {
            result = testDemo.getAppkeyList();
        }
        catch (AopTestException e) {
            result = new TestDemoResult(e.getCode(), e.getDetail(), "");
        }
        catch (Exception e) {
            e.printStackTrace();
            result = new TestDemoResult(TestDemoResult.ERROR_CODE, e.getMessage(), "");
        }
        return result;
    }

    /**
     * 根据工号获取工号对应的地市 渠道等信息
     * @param operatorId
     * @return
     * @throws Exception
     */
    @ResponseBody
    @RequestMapping("/getOperatorInfo.do")
    public TestDemoResult getOperatorInfo(String operatorId) throws Exception {
        TestDemoResult result = null;
        try {
            result = testDemo.getOperatorInfo(operatorId);
        }
        catch (AopTestException e) {
            result = new TestDemoResult(e.getCode(), e.getDetail(), "");
        }
        catch (Exception e) {
            e.printStackTrace();
            result = new TestDemoResult(TestDemoResult.ERROR_CODE, e.getMessage(), "");
        }
        return result;
    }

}
